﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Net.Http.Headers;
using DH.Core.UI.ViewModel;
using DH.Core;

namespace DH.Web.MVC.Controllers
{
    [Route("Error")]
    public class ErrorController : Controller
    {
        
        private IHostingEnvironment _env;

        public ErrorController(IHostingEnvironment env)
        {
            _env = env;
        }

        [Route("errors/{statusCode}")]
        public IActionResult CustomError(int statusCode)
        {

            //自定义错误页放在wwwroot下
            var filePath = $"{_env.WebRootPath}/errors/{(statusCode == 404 ? 404 : 500)}.html";
            return new PhysicalFileResult(filePath, new MediaTypeHeaderValue("text/html"));

            //return Content(new AjaxResult { Status = statusCode, Msg = "" }.ToJson());

            
        }
        [Route("page404")]
        public IActionResult Page404()
        {
            //自定义错误页放在wwwroot下
            var filePath = $"{_env.WebRootPath}/errors/404.html";
            return new PhysicalFileResult(filePath, new MediaTypeHeaderValue("text/html"));
        }
        [Route("page500")]
        public IActionResult Page500()
        {
            //自定义错误页放在wwwroot下
            var filePath = $"{_env.WebRootPath}/errors/500.html";
            return new PhysicalFileResult(filePath, new MediaTypeHeaderValue("text/html"));
        }
    }
}